<?php

    //设置响应头(编码格式)
    header("COntent-Type:text/html;charset=utf8");

    $username = $_POST['username'];
    $password = $_POST['password'];
    $email = $_POST['email'];


    $link = mysqli_connect('localhost','root','root','user');
    $res = mysqli_query($link,"SELECT * FROM `userinfo` WHERE `username` = '$username'");

    if(mysqli_fetch_assoc($res)){
        $arr = array(
            'status'=>0,
            'meta'=>[
                'msg'=>'用户名已存在',
                'data'=>null
            ]
        );
        echo json_encode($arr);
        exit;
    }

    mysqli_query($link,"insert into `userinfo` values('null','$username','$password','$email')");

    $brr = array(
        'status'=>1,
        'meta'=>[
            'msg'=>'注册成功!',
            'data'=>$username
        ]
    );
    echo json_encode($brr);
?>